#include "User.h"
#include "Team.h"
#include "TeamManager.h"
#include "ZStream.h"
#include "ServiceProvider.h"

#include <cassert>

User::User(ServiceProvider* i_sp, const std::string& i_name)
	: m_sp(i_sp),
	m_name(i_name)
{
	assert(m_sp);
}

ZStream& User::Serialize(ZStream& o_stream)
{
	o_stream.WriteOpenTag("User");
	o_stream.WriteAttribute("Name", m_name);
	o_stream.WriteAttribute("TeamID", m_team->GetID());
	o_stream.WriteCloseTag("User");
	return o_stream;
}

ZStream& User::Deserialize(ZStream& i_stream)
{
	i_stream.SkipLine();
	i_stream.ReadAttribute(m_name);

	size_t teamId;

	i_stream.ReadAttribute(teamId);
	m_team = m_sp->GetTeamMgr().GetTeamFromID(teamId);

	m_team->SetUserControlled(true);

	i_stream.SkipLine();
	return i_stream;
}